<template>
  <view>
    <view class="goods_item">
      <!-- 左侧盒子 -->
      <view class="left">
        <!-- 通过showRadio属性控制 radio标签是否显示 -->
        <radio :checked="item.goods_state" color="#C00000" v-if="showRadio" @click="handlClick"></radio>
       <image :src="item.goods_small_logo || defaultImg" mode=""></image>
      </view>
      <!-- 右侧盒子 -->
      <view class="right">
        <!-- 标题 -->
        <view class="right-title">
          {{item.goods_name}}
        </view>
        <!-- 价格 -->
        <view class="right-bottom">
          <view class="price">
            {{item.goods_price | tofixed(item.goods_price)}}
          </view>
          <view class="numb">
            <uni-number-box :min="1" :value="item.goods_count" v-if="showGoodsCount" @change="changeHandl"></uni-number-box>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    name:"my-goods",
    props:{
      item:{
        type:Object,
        default:{}
      },
      showRadio:{
        type:Boolean,
        default:false
      },
      showGoodsCount:{
        type:Boolean,
        default:false
      }
    },
    filters:{
      tofixed(num){
        return Number(num).toFixed(2)
      }
    },
    data() {
      return {
         defaultImg:'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
      };
    },
    methods:{
      handlClick(){
        this.$emit('radio-change',{
          goods_id:this.item.goods_id,
          goods_state:!this.item.goods_state
        })
      },
      changeHandl(val){
        this.$emit('numChange',{
          goods_id:this.item.goods_id,
          goods_count:+val
        })
      }
    }
  }
</script>

<style lang="scss">
.goods_item{
    display: flex;
    padding: 10px 5px;
    width: 750rpx;
    box-sizing: border-box;
    border-bottom: 1px solid #efefef;
    .left {
      margin-right: 5px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      image {
        width: 100px;
        height: 100px;
        display: block;
      }
    }
    .right {
      display: flex;
      flex: 1;
      flex-direction: column;
      justify-content: space-between;
      .right-title {
        font-size: 13px;
      }
      .right-bottom{
        display: flex;
        justify-content: space-between;
        .price {
          font-size: 16px;
          color: #C00000;
          font-weight: bold;
        }
      }
    }
  }
</style>